package com.example.bookproject.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
public class UserController {
    public void doController() {
        System.out.println("do controller ... ");
    }

    @RequestMapping("/login")
    public Boolean login(String userName, String password, HttpSession session) {
        if (!StringUtils.hasLength(userName) ||
                !StringUtils.hasLength(password)) {
            return false;
        }

        //验证数据库
        if ("admin".equals(userName) && "admin".equals(password)) {
            //账号密码正确设置session
            session.setAttribute("userName", userName);
            return true;
        }
        return false;
    }
}
